package com.tourlaid.mamagerment.ao.wx.impl

import com.tourlaid.mamagerment.ao.wx.MyThoughtAo
import com.tourlaid.mamagerment.enums.TldExceptionEnum
import com.tourlaid.mamagerment.service.StoreService
import com.tourlaid.mamagerment.service.ThoughtService
import com.tourlaid.mamagerment.util.LoginUtil
import com.tourlaid.mamagerment.util.TldException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/31.
 */
@Service("myThoughtAo")
class MyThoughtAoImpl : MyThoughtAo {

    @Resource
    val thoughtService: ThoughtService? = null
    @Resource
    val storeService: StoreService? = null

    @Transactional
    override fun delete(thoughtId: Long) {
        val thought = thoughtService!!.getById(thoughtId);
        if(!Objects.equals(thought.userId, LoginUtil.userId)){
            throw TldException(TldExceptionEnum.OTHER_THOUGHT)
        }
        thoughtService!!.delete(thoughtId)
        //修改店铺的说说数
        storeService!!.minusWhenThoughtDel(thought.storeId)
    }
}